#ifndef IMAGEWINDOW_H
#define IMAGEWINDOW_H

#include <QWidget>
#include <QFile>
#include <QFileInfo>
#include <QMessageBox>
#include <QTcpServer>
#include <QTcpSocket>
#include <QNetworkInterface>
#include <QBuffer>
#include <QThread>
#include <QTimer>


namespace Ui {
class ImageWindow;
}

// 图片传输协议头 (20字节)
struct ImageHeader {
    quint32 magic = 0x504E;  // PNG文件头标识 "‰PNG"
    quint32 width;               // 图片宽度
    quint32 height;              // 图片高度
    quint32 dataSize;            // 图片数据大小
};

class ImageWindow : public QWidget
{
    Q_OBJECT

public:
    explicit ImageWindow(QWidget *parent = nullptr);

    void setComponents(QString filename,QTcpSocket* tran_socket);
    ~ImageWindow();


    QString filename = nullptr;
    QImage image;
    QTimer *m_timer;
    QTcpSocket* tran_socket = nullptr;

private slots:
    // void do_timer_timeout(void);

    void on_pushButton_clicked();

    void on_pushButton_tcpTrans_clicked();

private:
    Ui::ImageWindow *ui;
    void  saveRGB888ToTxt(const QImage &image);
    void  sendImage( void);
    bool  waitForAck(QTcpSocket* socket, int timeoutMs ,QString ACK);
};

#endif // IMAGEWINDOW_H
